package com.bwie;

import java.util.ArrayList;
import java.util.List;

public class BookList1 {
    private List<Book> bookList=new ArrayList<>();

    public synchronized Book addBook(Book book){
        bookList.add(book);
        return book;
    }

    public synchronized Book getBook(int index){
        return bookList.get(index);
    }

    public synchronized Book removeBook(int index){
        return bookList.remove(index);
    }

    public void printAll(){
        for (Book book : bookList) {
            System.out.println(book);
        }
    }

    public static  void main(String[] args){
        BookList1 bookList1 = new BookList1();
        bookList1.addBook(new Book(1,"title","author","publisher"));
        bookList1.addBook(new Book(2,"title2","author","publisher"));
        bookList1.addBook(new Book(3,"title3","author","publisher"));

        System.out.println(bookList1.getBook(1));
        //删除 索引为1的图书
        bookList1.removeBook(1);
        //打印所有图书信息
        bookList1.printAll();
    }

}
